<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *群发邮件
 *@author : KevinBai
 *
 **/
class Testimport_model extends MY_Model
{
	public function __construct()
	{
		parent::__construct();
	}	
  /**
   * 生成试卷总况
   */
  public function createPater($data = [])
  {
      $this->db->insert("tr_test_paper", $data);
      return $this->db->insert_id();
  }
  /**
   * 试卷插入题目
   */
  public function insert_test_question($tr_test_question_data = [], $question = [])
  {
      $this->db->trans_start();
      //插入tr_test_question
      $this->db->insert("tr_test_question", $tr_test_question_data);
      $questionID = $this->db->insert_id();
      
      if($questionID && !empty($question[3]))
      {
          //插入题目选项
          $option_temp_arr = [];
          $option_arr = explode("<br />", $question[3]);
          foreach ($option_arr as $opkey => $option) {
              $option_temp_arr[] = '('.$questionID.',"'.trim($option).'")';
          }
          $option_temp_str =  implode(",", $option_temp_arr);
          $sql = "insert into tr_question_option (questionID,optionTitle) values {$option_temp_str}";
          $result = $this->db->query($sql);
      }
      //插入答案
      
      if($question[0])
      {
          $answers = $question[0];
          $answers_arr = explode(",",$answers);
          $answers = json_encode($answers_arr,JSON_NUMERIC_CHECK);
          $this->db->insert("tr_question_answer",['questionID'=>$questionID, 'answer'=>$answers]);
      }
      $this->db->trans_complete(); 
      return $this->db->trans_status() ;
  }
	/**
	 * 试卷生成选项
	 */
	public function insert_question_option($data = '')
	{
      $sql = "insert into tr_question_option (questionID,optionTitle) values {$data}";
      $resutl = $this->db->query($sql);
		  return $result;
	}
    
 
 
}

/* End of file emailsender_model.php */
/* Location: ./application/models/emailsender_model.php */
